package com.xuecheng.media.agent.hystrix;

import com.xuecheng.api.content.model.dto.TeachplanMediaDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.hystrix.BaseAPIHystrix;
import com.xuecheng.common.hystrix.BaseFallbackFactory;
import com.xuecheng.media.agent.ContentApiAgent;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

/**
 * Created on 2021/04/05/19:53 周一
 *
 * @author Lantin
 */

@Component
public class ContentApiAgentFallbackFactory extends BaseFallbackFactory<
        BaseAPIHystrix,
        ContentApiAgentFallbackFactory.ContentApiAgentHystrix,
        ContentApiAgentFallbackFactory.DevContentApiAgentHystrix> {

    /**
     * <p>
     * 生产环境降级方法类
     * </p>
     * 返回
     */
    public static class ContentApiAgentHystrix extends BaseAPIHystrix implements ContentApiAgent {


        public ContentApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<List<TeachplanMediaDTO>> getTeachplanMediaById(Long mediaId) {
            return super.baseFailResult();
        }
    }

    /**
     * <p>
     * 开发环境降级方法类
     * </p>
     * 返回一个默认值
     */
    public static class DevContentApiAgentHystrix extends BaseAPIHystrix implements ContentApiAgent {

        public DevContentApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<List<TeachplanMediaDTO>> getTeachplanMediaById(Long mediaId) {
            return RestResponse.success(Collections.emptyList());
        }
    }
}
